﻿using Microsoft.Extensions.Logging;
using System;
using TomNet.Attributes;

namespace TomNet.FreeSql
{
    [SingleInstance]
    public class SqlMonitor
    {
        private readonly IFreeSql _freeSql;
        private readonly ILoggerFactory _loggerFactory;
        private readonly ILogger _logger;
        public SqlMonitor(IFreeSql freeSql, ILoggerFactory loggerFactory)
        {
            _freeSql = freeSql;
            _loggerFactory = loggerFactory;
            _logger = _loggerFactory.CreateLogger(GetType());
            _freeSql.Aop.CurdBefore += (s, e) =>
            {
                _logger.LogInformation(e.Sql);
            };
        }
    }
}
